﻿CREATE PROCEDURE [dbo].[yaf_topic_findnext](
                @TopicID INT)
AS
    BEGIN
        DECLARE  @LastPosted DATETIME
        DECLARE  @ForumID INT
        SELECT @LastPosted = LastPosted,
               @ForumID = ForumID
        FROM   yaf_Topic
        WHERE  TopicID = @TopicID
        SELECT   TOP 1 TopicID
        FROM     yaf_Topic
        WHERE    LastPosted > @LastPosted
        AND ForumID = @ForumID
        AND (Flags & 8) = 0
        ORDER BY LastPosted ASC
    END


